//
//  RegisterViewController.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/18.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()
@property (nonatomic,strong)UIImageView *phoneImage;
@property (nonatomic,strong)UITextField *phoneNumberTF;//请输入手机号
@property (nonatomic,strong)UITextField *codeTF;//请输入验证码
@property (nonatomic,strong)UIButton *aquireCodeBtn; //获取验证码
@property (nonatomic,strong)UIButton *codeBtn;//验证
@property (nonatomic,strong)UILabel *lineLabel;

@end

@implementation RegisterViewController

- (UIImageView *)phoneImage{
    if (!_phoneImage) {
        _phoneImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 40, 30)];
        _phoneImage.image = [UIImage imageNamed:@"iconfont-phoneNumber"];

    }
    return _phoneImage;
}

- (UITextField *)phoneNumberTF{
    if (!_phoneNumberTF) {
        _phoneNumberTF = [[UITextField alloc]initWithFrame:CGRectMake(80, 100, 150, 30)];
        _phoneNumberTF.placeholder = @"请输入手机号码";
        [self.view addSubview:_phoneNumberTF];

    }
    return _phoneNumberTF;
}

- (UILabel *)lineLabel{
    if (!_lineLabel) {
        _lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 135, kWidth - 20, 1)];
        _lineLabel.backgroundColor = [UIColor lightGrayColor];
    }
    return _lineLabel;
}
- (UITextField *)codeTF{
    if (!_codeTF) {
        _codeTF = [[UITextField alloc]initWithFrame:CGRectMake(80, 150, 150, 30)];
        _codeTF.placeholder = @"请输入验证码";
        [self.view addSubview:_codeTF];

    }
    return _codeTF;
}
- (UIButton *)aquireCodeBtn{
    if (!_aquireCodeBtn) {
        _aquireCodeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _aquireCodeBtn.frame = CGRectMake(250, 100, 80, 30);
        [_aquireCodeBtn addTarget:self action:@selector(aquireCodeAction:) forControlEvents:UIControlEventTouchUpInside];
        [_aquireCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    }
    return _aquireCodeBtn;
}

- (UIButton *)codeBtn{
    if (!_codeBtn) {
        _codeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _codeBtn.frame = CGRectMake(250, 150, 50, 30);
        [_codeBtn addTarget:self action:@selector(codeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_codeBtn setTitle:@"验证" forState:UIControlStateNormal];
        [self.view addSubview:_codeBtn];

    }
    return _codeBtn;
}
- (void)aquireCodeAction:(UIButton *)sender{
    //SMSGetCodeMethodSMS：表示通过文本短信方式获取验证码
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.phoneNumberTF.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (error) {
            NSLog(@"wolfhous提交手机未成功%@",error);
        }else{
            NSLog(@"wolfhous提交手机号成功");
        }
    }];
}
- (void)codeBtnAction:(UIButton *)sender{

  [SMSSDK commitVerificationCode:self.codeTF.text phoneNumber:self.phoneNumberTF.text zone:@"86" result:^(SMSSDKUserInfo *userInfo, NSError *error) {
      if (error) {
          NSLog(@"wolfhous验证码失败%@",error);
      }else{
          NSLog(@"wolfhosu验证码成功");
      }

         PersonalCenterViewController *pcVC = [[PersonalCenterViewController alloc]init];
         [self.navigationController pushViewController:pcVC animated:YES];

  }];


}
- (void)viewDidLoad {

    [super viewDidLoad];
    [self.view addSubview:self.phoneImage];
    [self.view addSubview:self.phoneNumberTF];
    [self.view addSubview:self.codeTF];
    [self.view addSubview:self.aquireCodeBtn];
    [self.view addSubview:self.codeBtn];
    [self.view addSubview:self.lineLabel];

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
